package com.example.demo.mapper.entity;

import lombok.Data;

import javax.persistence.Id;
import javax.persistence.Table;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@Table(name="order")
public class Order {
    @Id
    private int orderId;
    private String orderNumber;
    private int studentId;
    private int commodityId;
    private int status;
    private int canceled;
    private int cancelReason;
    private String orderDate;
    private String shipDate;
    private String cancelDate;
    private String completeDate;
    private int distributeMethod;
    private String provinceId;
    private String cityId;
    private String areaId;//邮政编码
    private String address;
    private String contactName;
    private String contactPhone;
    private int pointsUsed;
    private String trackingNumber;
    private String notes;
    private int repertoryStatus;

    public void setOrderNumber() {
        // 生成随机数
        int randomNumber = (int) ((Math.random() * 100000000) + 1);

        // 获取当前时间作为前缀
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String datePrefix = sdf.format(new Date());

        // 拼接订单号
        orderNumber = datePrefix + String.format("%08d", randomNumber);
    }
}
